#include <stdio.h>
#include <stdlib.h>
#include "tuple.h"

struct stuple {
	key k;
	data d;
};

tuple tuple_fromKeyData (key k, data d) {
	tuple t = (tuple)calloc(1,sizeof(struct stuple));

	t->k = key_clone(k);
	t->d = data_clone(d);

	return t;
}

key tuple_fst (tuple t) {
	return (t->k);
}

data tuple_snd (tuple t) {
	return (t->d);
}

tuple tuple_clone (tuple t) {
	tuple f = (tuple)calloc(1,sizeof(struct stuple));

	if(f != NULL) {
		f->k = key_clone(t->k);
		f->d = data_clone(t->d);
	}

	return f;
}

tuple tuple_destroy (tuple t) {
	if(t != NULL){
		t->k = key_destroy(t->k);
		t->d = data_destroy(t->d);
		free(t);
		t = NULL;
	}

	return t;
}
